package org.wmq.shopmanager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wmq.commonutil.result.Result;
import org.wmq.shopmanager.service.SystemRoleService;
import org.wmq.shopmodel.DTO.system.SystemRoleDTO;
import org.wmq.shopmodel.Entity.system.SystemRole;

@RestController
@RequestMapping("/")
@RequiredArgsConstructor
public class SystemRoleController {
    private final SystemRoleService systemRoleService;

    @GetMapping("/getSystemRolePageItem")
    public Result<IPage<SystemRole>> getSystemRolePage(@ModelAttribute SystemRoleDTO systemRoleDTO){
        return Result.success(this.systemRoleService.getPageItem(systemRoleDTO));
    }

    @PostMapping
    public Result<Void> saveSystemRole(@RequestBody SystemRole systemRole){
        this.systemRoleService.save(systemRole);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<SystemRole> getSystemRoleById(@PathVariable Long id){
        return Result.success(this.systemRoleService.getById(id));
    }
    @PutMapping
    public Result<Void> updateSystemRole(@RequestBody SystemRole systemRole){
        this.systemRoleService.updateById(systemRole);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result<Void> deleteSystemRoleById(@PathVariable Long id){
        this.systemRoleService.removeById(id);
        return Result.success();
    }
}
